{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import Annotated\n",
    "from typing_extensions import TypedDict\n",
    "from langgraph.graph import StateGraph,START,END\n",
    "from operator import add\n",
    "from langgraph.types import Send\n",
    "\n",
    "class State(TypedDict):\n",
    "    foo: Annotated[list[str], add]\n",
    "    f:str\n",
    "\n",
    "\n",
    "def agent_01(state):\n",
    "    return {\"foo\": [state[\"f\"]]}\n",
    "\n",
    "def dispatch(state):\n",
    "    return [Send(\"node_01\",{\"f\":str(_x)}) for _x in range(6)]\n",
    "\n",
    "\n",
    "\n",
    "_buider = StateGraph(State)\n",
    "\n",
    "_buider.add_node(\"node_01\", agent_01)\n",
    "\n",
    "_buider.add_conditional_edges(START,dispatch)\n",
    "_buider.add_edge(\"node_01\",END)\n",
    "\n",
    "\n",
    "_graph = _buider.compile()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'foo': ['0', '1', '2', '3', '4', '5'], 'f': ''}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "_graph.invoke({\"foo\":[],\"f\":\"\"})"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python310",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
